package com.mochasoft.shangchm;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import com.mochasoft.shangchm.analyzer.AnalyzerFactory;
import com.mochasoft.shangchm.analyzer.ColLineAnalyzer;
import com.mochasoft.shangchm.analyzer.ElevenAnalyzer;
import com.mochasoft.shangchm.analyzer.LineAnalyzer;
import com.mochasoft.shangchm.analyzer.LinkAnalyzer;
import com.mochasoft.shangchm.analyzer.SameTailAnalyzer;
import com.mochasoft.shangchm.stop.Filter;
import com.mochasoft.shangchm.stop.StopFilter;
import com.mochasoft.shangchm.type.CaiPiaoFactory;
import com.mochasoft.shangchm.type.ICaiPiao;

public class Goodluck {
	
	public Goodluck(){
		//AnalyzerFactory.getInstance().addAnalyzer("eleven", new ElevenAnalyzer());
		//AnalyzerFactory.getInstance().addAnalyzer("line", new LineAnalyzer());
		//AnalyzerFactory.getInstance().addAnalyzer("colline", new ColLineAnalyzer());
		//AnalyzerFactory.getInstance().addAnalyzer("jo", new JOAnalyzer());
		AnalyzerFactory.getInstance().addAnalyzer("link", new LinkAnalyzer());
		AnalyzerFactory.getInstance().addAnalyzer("sametail", new SameTailAnalyzer());
	}
	
	public Set makeGoodluck(ICaiPiao cp,int i){
		return cp.getResult(i);
	}
	
	public Filter getFilter(String stopNumbers,String path) throws IOException{
		Filter filter = new StopFilter(stopNumbers);
		if(filter.getStopNumbers().size()==0){
			filter = new StopFilter(new File(path));
		}
		return filter;
	}
	
	public Map getAnalyzers(Set keys){
		if(keys==null){
		    return AnalyzerFactory.getInstance().getAnalyzers();
		}else{
		    return AnalyzerFactory.getInstance().getAnalyzers(keys);
		}
	}
	
	public Set makeGoodNumber(int maxNumber,Filter filter){
		Set StopNumers = filter.getStopNumbers();
		Set goodNumbers = new TreeSet();
		for(int i = maxNumber;i>0;i--){
			if(!StopNumers.contains(new Integer(i))){
				goodNumbers.add(new Integer(i));
			}
		}
		return goodNumbers;
	}
	
	
	public static void main(String[] args) throws IOException {
		Goodluck gl = new Goodluck();
		ICaiPiao caipiao_r = CaiPiaoFactory.getInstance().getCaiPiaoInstance("flcp_r");
		Filter filter = gl.getFilter("21 10 32 13 01 29", null);
		caipiao_r.setFilter(filter);
		caipiao_r.setAnalyzers(gl.getAnalyzers(null));
		Set set = caipiao_r.getResult(1);
		Iterator iter = set.iterator();
		while(iter.hasNext()){
			System.out.println(iter.next());
		}
		System.out.println(gl.makeGoodNumber(33,filter));// 06 08 11 13 17 19
	}

}
